package com.jz.reservoirattributesclass.conroller;

//import com.jz.subclass.test.SubStatusEnum;

import com.jz.reservoirattributesclass.model.ReservoirattributesAddVo;
import com.jz.reservoirattributesclass.model.ReservoirattributesSelectVo;
import com.jz.reservoirattributesclass.model.ReservoirattributesUpdateStatusVo;
import com.jz.reservoirattributesclass.model.ReservoirattributesUpdateVo;
import com.jz.reservoirattributesclass.service.ReservoirattributesService;
import com.jz.util.ResultBuildVo;
import com.jz.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * Created by WISE on 2021/12/26.
 */
@RestController
@CrossOrigin//开启跨域
public class ReservoirattributesController {


    //1.首页分页
    @Autowired
    private ReservoirattributesService reservoirattributesService;

    @PostMapping("pickingArea/queryPage")
    public ResultVo firstPage(@RequestBody ReservoirattributesSelectVo reservoirattributesSelectVo) {
        ResultVo resultVo = reservoirattributesService.firstPage(reservoirattributesSelectVo);

        return resultVo;
    }

    //2.新增
    @PostMapping("pickingArea/add")
    @Transactional
    public ResultVo add(@RequestBody @Valid ReservoirattributesAddVo partAddVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = reservoirattributesService.addpartClass(partAddVO);
        return resultVo;
    }

   @PostMapping("pickingArea/update")
    public ResultVo update(@RequestBody @Valid ReservoirattributesUpdateVo partUpdateVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
       return reservoirattributesService.updateSubClass(partUpdateVo);
   }

    @PostMapping("pickingArea/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid ReservoirattributesUpdateStatusVo partUpdateStatusVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return reservoirattributesService.updateStatus(partUpdateStatusVo);
    }

}



